<template>
    <div class="div">
        &nbsp;&nbsp;人员信息
    </div>
    <table id="person" cellspacing="0" style="width: 100%;height: 50px;border: 1px solid #a8aeb2;">        
        <tr class="tr" v-for="pers in labRecordPerList">
            <th v-for="per in pers.itemsRecordPersonList" class="thE" :rowspan="per.fieldRowspan > 0 ? per.fieldRowspan : 1"  :colspan="per.fieldColspan > 0 ? per.fieldColspan : 1">
                <span v-if="per.fieldInput === '0'">{{ per.fieldName }}</span>
                <a-input :name="per.fieldCode" v-else-if="per.fieldInput === '1' && (per.fieldCode === 'check_person' || per.fieldCode === 'person_value1')" :readonly="per.fieldCode === 'check_person' ? true : false" v-model:value="per.fieldValue" size="large" class="input" />
                <!-- <a-input :name="per.fieldCode" v-else-if="per.fieldInput === '1' && (per.fieldCode === 'audit_person' || per.fieldCode === 'person_value2')" :readonly="per.fieldCode === 'audit_person' ? true : false" :value="per.fieldValue" size="large" class="input" @click="handleUserModal"  @getSelectResult="onSelectOk" /> -->
                <a-input :name="per.fieldCode" v-else-if="per.fieldInput === '1' && (per.fieldCode === 'audit_person' || per.fieldCode === 'person_value2')" :readonly="per.fieldCode === 'audit_person' ? true : false" :value="per.fieldValue" size="large" class="input" @getSelectResult="onSelectOk" />
            </th>
        </tr>
    </table>
    <TableUserModal @register="registerUserModal" @getSelectResult="onSelectOk"></TableUserModal>
</template>
  
<script lang="ts" setup>
import { reactive } from 'vue';
import { useModal } from '/@/components/Modal';
import TableUserModal from './LabUserTableList.vue';


const props = defineProps<{
    labRecordPerList: [{
        pId: String | number,
        itemsRecordPersonList: [{
            id: String | number,
            createBy: String,
            createTime: String,
            updateBy: String,
            updateTime: String,
            sysOrgCode: String,
            taskId: String,
            itemId: String,
            fieldName: String,
            fieldCode: String,
            fieldValue: String,
            fieldInput: String | number,
            fieldSort: number,
            fieldType: String,
            fieldRow: number,
            fieldCol: number,
            fieldRowspan: number,
            fieldColspan: number,
        }]
    }],
}>();

const formPerData = reactive<Record<string, any>>({
    auditId: "",
    auditName: "",
});

const [registerUserModal, { openModal }] = useModal();


function handleUserModal() {
    openModal(true);
}


function onSelectOk(uId, uName) {
    //处理业务逻辑
    formPerData.auditId = uId;
    formPerData.auditName = uName;
    for (var i = 0; i < props.labRecordPerList.length; i++) {
        const itemsRecordPersonList = props.labRecordPerList[i].itemsRecordPersonList;
        for (var z = 0; i < itemsRecordPersonList.length; z++) {
            if (itemsRecordPersonList[z].fieldCode === "audit_person" || itemsRecordPersonList[z].fieldCode === "person_value2") {
                itemsRecordPersonList[z].fieldValue = uName;
                break;
            }
        }
    }
}


defineExpose({
    props,
    formPerData
});



</script>
  
<style scoped>
.div {
    height: 45px;
    border: 1px solid #a8aeb2;
    background-color: #d2d5d6;
    text-align: left;
    font: 1.2em sans-serif;
    line-height: 45px
}

.tr {
    height: 50px;
    border: 1px solid #a8aeb2;
}

.thE {
    width: 25%;
    text-align: center;
    border: 1px solid #a8aeb2;
    font: 1.2em sans-serif;
}

.input {
    width: 100%;
    height: 100%;
    border: none;
    background-color: inherit;
    outline: none;
    border-bottom: none;
}</style>